
-module(tup2).
-export([oddsEvens/1, max/2, odds_and_evens/1 convert_length/1, len1/1, len2/2, examp/1, bubble/1, perms/1]).

oddsEvens(L) ->
	oddsEvens(L, [], []).
oddsEvens([H|T], Odds, Evens) ->
	case (H rem 2) of
		1 -> oddsEvens(T, [H|Odds], Evens);
		0 -> oddsEvens(T, Odds, [H|Evens])
	end;
oddsEvens([], Odds, Evens)->
	{Odds, Evens}.


odds_and_evens(L) ->
	Odds  = [X || X <- L, (X rem 2) =:= 1],
	Evens = [X || X <- L, (X rem 2) =:= 0],
	{Odds, Evens}.

convert_length({centimeter, X}) ->
	{inch, X / 2.54};
convert_length({inch, Y}) ->
	{centimeter, Y * 2.54}.

len1([]) -> 0;
len1([H|T]) -> 1 + len1(T).

len2([], 1) -> 0;
len2([H|T], 1) -> len2(T, 1) + 1.

examp([E1,E2 | T]) -> {E1, E2}.

bubble([]) -> [];
bubble([F | T]) -> 
	bubble([E || E <- T, F > E])
	++[F].

perms([]) -> [[]];
perms(L) ->[[H|T] || H <- L, T <- perms(L -- [H])].

max(X, Y) when X > Y -> X;
max(X, Y) -> Y.